package nju.bishe.weibo;

import java.util.List;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListView;

import nju.bishe.weibo.adapter.UserArrayAdapter;
import nju.bishe.weibo.data.User;
import nju.bishe.weibo.ui.base.UserCursorActivity;
import weibo4android.Paging;
import weibo4android.WeiboException;

public class SuggestionResultActivity extends UserCursorActivity {

	private ListView mUserList;
	private UserArrayAdapter mAdapter;
	private String userId;
	private static final String LAUNCH_ACTION = "nju.bishe.weibo.SuggestionResult";
	private static final String TAG = "SuggestionResultActivity";
	private static final String USER_ID = "userId";
	private int currentPage = 1;
	String myself = "";
	private String category = "default";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Intent intent = getIntent();
		Bundle extras = intent.getExtras();
		Log.i(TAG, category);
		if (extras != null) {
			this.userId = extras.getString(USER_ID);
			this.category = extras.getString("category");
		} else {
			// 获取登录用户id
//			SharedPreferences preferences = PreferenceManager
//					.getDefaultSharedPreferences(this);
//			userId = preferences.getString(Preferences.CURRENT_USER_ID,
//					TwitterApplication.mApi.getUserId());
			userId=TwitterApplication.getMyselfId();
		}
		Uri data = intent.getData();
		if (data != null) {
			userId = data.getLastPathSegment();
		}
		
		super.onCreate(savedInstanceState);
		
		myself = TwitterApplication.getMyselfId();
		if(getUserId()==myself){
			setHeaderTitle("我还可以关注谁？");
		}
		
		
		
		

	}

	/*
	 * 添加取消关注按钮
	 * 

	 */
	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		super.onCreateContextMenu(menu, v, menuInfo);
		if (getUserId() == myself) {
			AdapterView.AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
			User user = getContextItemUser(info.position);
			menu.add(0, CONTENT_ADD_FRIEND, 0, getResources().getString(
					R.string.cmenu_user_addfriend_prefix)
					+ user.screenName
					+ getResources().getString(
							R.string.cmenu_user_friend_suffix));

		}

	}

	public static Intent createIntent(String userId) {
		Intent intent = new Intent(LAUNCH_ACTION);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		intent.putExtra(USER_ID, userId);
		return intent;
	}

	@Override
	public Paging getNextPage() {
		currentPage += 1;
		return new Paging(currentPage);
	}

	@Override
	protected String getUserId() {
		return this.userId;
	}

	@Override
	public Paging getCurrentPage() {

		return new Paging(this.currentPage);
	}

	@Override
	protected List<weibo4android.User> getUsers(String userId, Paging page,int type)
			throws WeiboException {

		return getApi().getHotUsers(category);

	}

	@Override
	protected List<User> fetchUsersFromDb(String ownerId) {
		// TODO Auto-generated method stub
		return null;
	}

}
